<?php

//require_once 'PHPUnit/Framework/TestCase.php';
require_once __DIR__."/../../lib/brenda_template.php";


class Brenda_Template_Test extends PHPUnit_Framework_TestCase {
	
	private $b1;
	
	private $b2;
	
	private $b3;
	
	protected function setUp() {
		
		parent::setUp (); 
		
		$this->b1 = new Brenda_Template(__DIR__."/bt_template/template_1.json");
		
		$file = file_get_contents(__DIR__."/bt_template/template_1.json");
		
		$this->b2 = new Brenda_Template($file);
		
		$this->b3 = new Brenda_Template(__DIR__."/bt_template/template_3.json");
	}
	
	protected function tearDown() {
		parent::tearDown ();
	}
	
	public function testBrendaTwoBlock(){
		$count_block = count($this->b1->get_blocks_info());
		
		$this->assertTrue($count_block == 2);
		
		$this->assertTrue($this->b1->get_state() == true);
	}

	public function testBrendaErrorTwoBlock(){
		
		$bt = new Brenda_Template( __DIR__."/bt_template/template_2.json" );
		
		$this->assertTrue( $bt->get_state() == null );	
	}
	
	public function testBrendaTokensFound(){
		
		$tokens = $this->b1->get_tokens_info();
		
		$tokens_block_1_count = count($tokens[0]);
		
		$tokens_block_2_count = count($tokens[1]);

		$this->assertTrue($tokens_block_1_count == 7, "total tokens en el bloque 1: ".$tokens_block_1_count." ".$this->b1->get_lasted_error());
		
		$this->assertTrue($tokens_block_2_count == 13, "total tokens en el bloque 2: ".$tokens_block_2_count." ".$this->b1->get_lasted_error());
	}
	
	public function testBrendaTonkensInVar(){
		
		$blocks = $this->b2->get_blocks_info();
		
		$blocks_count = count($blocks);
		
		$this->assertTrue($blocks_count == 2,"total de bloques:".$blocks_count);
		
	}
	
	public function testBrendaSintacticAnalizer(){
		
		if($this->b1->get_state() == false){
			
			$this->assertTrue(true == false,$this->b1->get_lasted_error());
		}
	}
	
	public function testBrendaTemplate3(){
		
		//var_dump($this->b3->get_tokens_info());
		
		//prueba
		
		$this->assertTrue($this->b3->get_state() == true,$this->b3->get_lasted_error());
		
	}
	
}

